﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class inc_left : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        init();
    }
    protected void init()
    {
        String channel = "";
        if (Request["channel"] != null && Request["channel"].Trim().Length > 0)
        {
            channel = Request["channel"].Trim();
        }
        else if (Request["id"] != null && Request["id"].Trim().Length > 0)
        {
            //提取信息所属栏目页面位置
            DataTable dt = NewDao.findChanelByNewId(Request["id"].Trim());
            if (dt != null && dt.Rows.Count > 0)
            {
                channel = dt.Rows[0]["pageLocation"].ToString();
            }
        }
        if (channel != null && channel.Trim().Length > 0)
        {
            DataTable channelDt = ChannelDao.findByPL(channel);
            if (channelDt != null && channelDt.Rows.Count > 0)
            {
                String sql = "";
                if (channelDt.Rows[0]["father_id"].ToString().Equals("1"))
                {
                    //如果有子栏目则显示第一个子栏目的内容
                    sql = "select top 1 url,pageLocation from channel where father_id=" + channelDt.Rows[0]["channel_id"].ToString() + " and is_show='0' order by show_order";
                    DataTable dt = DB.getDataTable(sql);
                    if (dt != null && dt.Rows.Count > 0) {
                        Response.Redirect(dt.Rows[0]["url"].ToString() + (dt.Rows[0]["url"].ToString().IndexOf("?") > -1 ? "&" : "?") + "channel=" + dt.Rows[0]["pageLocation"].ToString());
                    }
                    //sql = "select url,name,pageLocation from channel where father_id=" + channelDt.Rows[0]["channel_id"].ToString() + " and is_show='0' order by show_order";
                }
                else
                {
                    sql = "select url,name,pageLocation from channel where father_id=" + channelDt.Rows[0]["father_id"].ToString() + " and is_show='0' order by show_order";
                }
                DB.bindData(sql, channelData);
            }
        }
    }
}
